package com.ibm.moa.outmail.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.ScrollView;

public class MyScrollView extends ScrollView {

	public MyScrollView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public MyScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public MyScrollView(Context context) {
		super(context);
	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		MessageWebView webView = (MessageWebView) findViewWithTag("webview");
		LinearLayout webview_layout = (LinearLayout) findViewWithTag("webview_layout");
		if (webView != null) {
			int top = webview_layout.getTop();
			int scrollY = getScrollY();
			ev.offsetLocation(0, -top + scrollY);
			webView.dispatchTouchEvent(ev, false);
			ev.offsetLocation(0, top - scrollY);
		}
		return super.dispatchTouchEvent(ev);
	}

	@Override
	public void requestChildFocus(View child, View focused) {
		if (focused instanceof WebView)
			return;
		super.requestChildFocus(child, focused);
	}
}
